#include "linkedList.h"

using namespace DataStructures;
using namespace std;

LinkedList::LinkedList()
{
	numberOfItems = 0;
}

LinkedList::~LinkedList()
{

}

void LinkedList::Insert(bool recursive, int data)
{
	if(recursive)
	{
		if(firstNode == NULL)
		{	
			firstNode = new LinkedListNode(data);
			numberOfItems++;
		}
		else
			Insert(firstNode, data);
	}
	else{
		if(firstNode == NULL)
			firstNode = new LinkedListNode(data);
		else
		{
			LinkedListNode* node = firstNode;

			while ((*node).next != NULL)
			{
				node = (*node).next;
			}

			(*node).next = new LinkedListNode(data);
		}		
	}
}

bool LinkedList::Insert(LinkedListNode* node, int data)
{
	if((*node).next == NULL)
	{
		(*node).next = new LinkedListNode(data);
		numberOfItems++;	

		return true;
	}
	else
		return Insert((*node).next, data);	
}

void LinkedList::Delete(int data)
{

}

bool LinkedList::Delete(LinkedListNode* node, int data)
{
	if(!node)
		return false;
	else if((*node).GetData() != data)
		Delete((*node).next, data);
	else
		;//
}

void LinkedList::PrintList(bool recursive)
{
	if(recursive)	
	{
		if(firstNode == NULL)
			cout << "The list is empty";
		else	
			cout << "{ " + PrintList(firstNode) << " }" << endl;	
	}
	else
	{
		if(firstNode == NULL)
			cout << "The list is empty" << endl;
		else
		{
			LinkedListNode* node = firstNode;

			cout << to_string((*node).GetData());			
			node = (*node).next;

			while (node != NULL)
			{
				cout << ", " << to_string((*node).GetData());			
				node = (*node).next;
			}
		}
	}
}

string LinkedList::PrintList(LinkedListNode* node)
{
	if((*node).next == NULL)

		return to_string((*node).GetData());
	else
		return to_string((*node).GetData()) + ", " + PrintList((*node).next);
}